<template>
  <div class="commentwrap">
    <div class="ebooksContent">
      <commentCom ref="commentCom" :prodType="ckFrom.ebooks" :prodId="ebId"></commentCom>
    </div>
    <!-- 底部 -->
    <div class="c-pf c-p-b0 c-p-l0 c-w100 comment-btn c-bg-white" @click="addComment()" >
      <div class="c-flex-row c-aligni-center c-justify-center c-hh100 c-fc-smblue">
        <i class="iconfont">&#xe99d;</i>
        <span class="c-ml12 c-fs24">写评论</span>
      </div>
    </div>
  </div>
</template>

<script>
import { utilJs } from "@/utils/common.js";
import commentCom from "@/components/templates/common/commentCom.vue";
export default {
  name: "EbooksComment",
  components: {
    commentCom
  },
  data() {
    return {
      cfg: JSON.parse(localStorage.getItem("cfg")),
      ckFrom: global.ckFrom,
      ebId: '',
      ebooksShar: null,
    }
  },
  created() {
    utilJs.appShare(this);
  },
  activated() {
    setDocumentTitle("电子书评论");
    this.ebId = this.$route.query.ebId;
    this.ebooksShar = null;
    this.$nextTick(() => {
      this.$refs.commentCom && this.$refs.commentCom.public_initData()
    })
    this.getEbookShare();
  },
  methods: {
    addComment() {
      this.$nextTick(() => {
        if (this.$refs.commentCom) {
          this.$refs.commentCom.public_addComment()
        }
      })
    },
    // 获取电子书分享内容
    getEbookShare() {
      let postUrl = `${global.apiurl}ebooks/getEbookShare/${this.ebId}`;
      utilJs.getMethod(postUrl, res => {
        this.ebooksShar = res;
        this.wechatShare();
      })
    },
    wechatShare: function () {
      let title = this.ebooksShar.name || window.localStorage.getItem("shareTitle");
      let shareImg = this.ebooksShar.avatar || window.localStorage.getItem("shareLogo");
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?ebId=${this.ebId}&refereeId=${localStorage.getItem("userId")}`;
      let shareDesc = this.ebooksShar.shareDesc || '点击查看详情';
      utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc);
    },
    //手机端分享
    appShare: function () {
      let title = this.ebooksShar.name || window.localStorage.getItem("shareTitle");
      let shareImg = this.ebooksShar.avatar || window.localStorage.getItem("shareLogo");
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?ebId=${this.ebId}&refereeId=${localStorage.getItem("userId")}`;
      let shareDesc = this.ebooksShar.shareDesc || '点击查看详情';
      utilJs.appShareTrue(title, shareImg, shareUrl, shareDesc);
    }
  },
}
</script>

<style lang="less" scoped>
.commentwrap {
  width: 100%;
  height: 100%;
  .ebooksContent {
    width: 100%;
    padding-bottom: 2.5rem;
  }
}
.wrap {
  white-space: normal;
  word-break: break-all;
}
.comment-btn {
  box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
}
</style>